package com.expert.conrtoller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.expert.annotations.RoleAnnotation;
import com.expert.context.BaseContext;
import com.expert.dto.AddNoticeDTO;
import com.expert.dto.TitleDTO;
import com.expert.enums.RoleLevel;
import com.expert.pojo.Title;
import com.expert.result.Result;
import com.expert.service.TitleService;
import com.expert.vo.NoticeVo;
import com.expert.vo.TitleVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @ClassName: TitleController
 * @Author: cxs
 * @Date: 2024/03/21 15:55
 * @Description:
 **/
@RestController
@RequestMapping("/title")
@Slf4j
public class TitleController {
    @Autowired
    TitleService titleService;

    @RoleAnnotation(level = RoleLevel.ADMIN)
    @GetMapping("/page")
    public Result<Page<TitleVo>> pageNotice(Integer page, Integer pageSize, String titleName, Integer titleLevel){
        log.info("分页查询");

        Page<TitleVo> titleVoPage=this.titleService.pageTitle(page,pageSize,titleName,titleLevel);
        return Result.success(titleVoPage);
    }

    @RoleAnnotation(level = RoleLevel.ADMIN)
    @PostMapping("/addTitle")
    public Result addTitle(@RequestBody TitleDTO title){
        log.info("添加职称:{}",title);
        this.titleService.addTitle(title);
        return Result.success();
    }
    @RoleAnnotation(level = RoleLevel.ADMIN)
    @GetMapping("/{id}")
    public Result<Title> getByTitle(@PathVariable("id") Long id){
        return Result.success(this.titleService.getById(id));
    }
    @RoleAnnotation(level = RoleLevel.ADMIN)
    @PutMapping("/update")
    public Result update(@RequestBody Title title){
        title.setUpdateUser(BaseContext.getCurrentId());
        title.setUpdateTime(LocalDateTime.now());
        this.titleService.updateById(title);
        return Result.success();
    }
    @RoleAnnotation(level = RoleLevel.ADMIN)
    @DeleteMapping("/delete")
    public Result deleteTitle(@RequestParam List<Long> ids){
        this.titleService.deleteTitles(ids);
        return Result.success();
    }
    @GetMapping("/all")
    public Result<List<Title>> getTitle(){
        return Result.success(this.titleService.list());
    }
}
